<?php

include_once("Database.inc");

class AccessLevel {
	
	public $id;
	public $description;
	
	/*
	 * Obtains an array of all available access levels.
	 */
	public static function getAllAccessLevels() {
		$levels = array();
		
		$query = $GLOBALS["DB"] -> doQuery("SELECT ACCESSLEVEL, ACCESSLEVELDESC FROM SECURITYACCESSLEVEL");
		
		while ($row = mssql_fetch_array($query)) {
			array_push($levels, AccessLevel::getAccessLevelFromArray($row));
		}
		
		return $levels;
	}
	
	/*
	 * Obtains the Access Level with the specified ID.
	 */
	public static function getAccessLevel($id) {
		$query = $GLOBALS["DB"]->doQuery("SELECT ACCESSLEVEL, ACCESSLEVELDESC FROM SECURITYACCESSLEVEL WHERE ACCESSLEVEL = $id");	 
		
		if ($row = mssql_fetch_array($query)) {
			return AccessLevel::getAccessLevelFromArray($row);
		} else {
			return null;
		}
	}
	
	/*
	 * Creates a AccessLevel object from a database record.
	 */
	protected static function getAccessLevelFromArray($array) {
		$al = new AccessLevel();
		
		$al->id = $array[0];
		$al->description = $array[1];
		
		return $al;
	}
}

?>
